package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;
import javax.swing.UIManager;

import controllers.DBConnection;

import java.awt.Color;
import java.sql.ResultSet;

import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Samples extends JFrame {

	private JPanel contentPane;
	private JTable table;
	static String ID;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Samples frame = new Samples();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Samples() {
		setTitle("Samples");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 629, 365);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(69, 40, 386, 179);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setBounds(69, 270, 87, 23);
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		JButton btnBack = new JButton("Back");
		btnBack.setBounds(177, 270, 87, 23);
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CustomerGui frame = new CustomerGui(ID);
				frame.setVisible(true);
				dispose();
			}

		});
		
		DefaultTableModel model=new DefaultTableModel();
		JTable table=new JTable(model);
		table.setModel(new DefaultTableModel(
			new Object[][] {
				
			},
			new String[] {
				"Picture Place", "Picture Time"
			}
		));
		scrollPane.setViewportView(table);
		contentPane.setLayout(null);
		contentPane.add(btnCancel);
		contentPane.add(btnBack);
		contentPane.add(scrollPane);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon("images//bla.jpg"));
		lblNewLabel.setBounds(0, 0, 613, 326);
		contentPane.add(lblNewLabel);
		lblNewLabel.setLayout(null);
		
		
		
	
		
	
	}
	private void Update_table(){

		try{
				/*sql connection*/
				DBConnection conn=new DBConnection();
				java.sql.PreparedStatement pr1= conn.getDBConnection().prepareStatement("SELECT picPlace,picTime " + "FROM sgi_system.archive " );
				ResultSet rs=pr1.executeQuery();
				int i=0;
			while (rs.next()){
				String Place=rs.getString("picPlace");
				String Time=rs.getString("picTime");
				System.out.println(""+Place);
				int numCols=table.getModel().getColumnCount();
				Object[] SamplesTable=new Object[numCols];
				SamplesTable[i]=Place;
				((DefaultTableModel)table.getModel()).addRow(SamplesTable);
				System.out.println(""+SamplesTable[i]);
				i++;
			}
			
						
		}//try
			catch (Exception e){e.printStackTrace();}
 
 

		
		
	}
}
